﻿using System;
using System.Configuration;
using System.Web.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PRDP.Tools;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using PRDP;

public partial class _Default : System.Web.UI.Page 
{
    //页面标题
    string webSiteName = CommonConfig.getInstance().getPerpertyValue("websiteName");
    //最大显示分类数目
    int maxDisplayNum = 6;
    //搜索分类编号
    string searchTypeID;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] == null || Request["id"] == "")
            this.searchTypeID = MyDBHandler.getOne("select top 1 ID from Type where PID=-1 and Display='true' order by Rank asc")["ID"].ToString();
        else
            this.searchTypeID = Request["id"];

        loadFooterHTML(phFootHTML, "~/userControl/Foot.ascx");
        laSearchList.Text = generateSearchType();
        Page.ClientScript.RegisterStartupScript(this.GetType(), "searchList", "$Obj('searchType').value='" + this.searchTypeID + "';"
            + "indexSearchType='" + this.searchTypeID + "';"
            , true);
        literalTitle.Text = webSiteName;
    }

    public string generateSearchType()
    {
        string searchTypeHTML = string.Empty;
        List<Hashtable> rows = MyDBHandler.getAllList("select top " + this.maxDisplayNum.ToString() + " CnName,ID from Type where Display='true' order by Rank asc");
        //指定ID是否在显示列表中
        bool isSpecialTypeDisplay = false;
        foreach (Hashtable row in rows)
        {
            string className = "textA";
            if (row["ID"].ToString() == this.searchTypeID)
            {
                className = "strong3";
                isSpecialTypeDisplay = true;
            }               
            searchTypeHTML += "<td align=middle><a id=\"indexA" + row["ID"].ToString() + "\" class=\"" + className + "\" href=\"#\" onclick=\"selectSearchType(this,'" + row["ID"].ToString() + "')\">" + row["CnName"].ToString() + "</a> </td>\r\n";
        }
        if (!isSpecialTypeDisplay)
        {
            string specialTypeName = MyDBHandler.getOne("select CnName from Type where ID=" + this.searchTypeID)["CnName"].ToString();
            searchTypeHTML += "<td align=middle><a id=\"indexA" + this.searchTypeID + "\" class=\"strong3\" href=\"#\" onclick=\"selectSearchType(this,'" + this.searchTypeID + "')\">" + specialTypeName + "</a> </td>\r\n";
        }
        return searchTypeHTML;
    }



    public void loadFooterHTML(PlaceHolder ph,string ctrlPath)
    {
        UserControl uc = new UserControl();
        Control ctrl = uc.LoadControl(ctrlPath);
        ph.Controls.Add(ctrl);
    }
}
